import { createStore } from "vuex";
import { LoginTokenObj, UserInfo } from "@/types/type";
import myPlugins from "./myPlugins";

export default createStore({
  state: {
    tokenObj: {} as LoginTokenObj,
    userInfo: {} as UserInfo,
  },
  mutations: {
    setTokenObj(state: any, obj: any) {
      state.tokenObj = obj;
    },
    setUserInfo(state: any, obj: any) {
      state.userInfo = obj;
    },
    // 清空所有数据
    clearAll(state: any) {
      state.tokenObj = {};
      state.userInfo = {};
    },
  },
  getters: {
    tokenObj: (state: any) => state.tokenObj,
    userInfo: (state: any) => state.userInfo,
  },
  actions: {}, // 异步修改数据，定义方法
  modules: {}, // 修改数据，定义方法
  plugins: [myPlugins], //持久化数据，防止数据丢失
});
